package com.loubobooo.personal.blog.service.impl;

import com.loubobooo.personal.blog.entity.Notice;
import com.loubobooo.personal.blog.entity.vo.NoticeVO;
import com.loubobooo.personal.blog.mapper.NoticeMapper;
import com.loubobooo.personal.blog.mapper.custom.NoticeMapperCustom;
import com.loubobooo.personal.blog.service.NoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service public class NoticeServiceImpl implements NoticeService {

    @Autowired private NoticeMapperCustom noticeMapperCustom;

    @Autowired private NoticeMapper noticeMapper;

    @Override public List<NoticeVO> listNotice(Integer status) {
        return noticeMapperCustom.listNotice(status);
    }

    @Override public void insertNotice(Notice notice) {
        noticeMapper.insertSelective(notice);
    }

    @Override public void deleteNotice(Integer id) {
        noticeMapper.deleteByPrimaryKey(id);
    }

    @Override public void updateNotice(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override public NoticeVO getNoticeById(Integer id) {
        Notice notice = noticeMapper.selectByPrimaryKey(id);
        NoticeVO noticeVO = new NoticeVO();
        BeanUtils.copyProperties(notice, noticeVO);
        return noticeVO;
    }

}
